#include <stdio.h>
#include <stdlib.h>
#include "automata2.h"
#include "util.h"

void
printMatrix(t_matrix * mat)
{
    int i,j;
    for(i=0;i<mat->fils;i++)
    {
        for(j=0;j<mat->cols;j++)
            printf("%d\t",mat->data[i][j]);
        printf("\n");
    }
}

void
printAlphabet(t_table * t)
{
    int i=0;

	printf("\nAlphabet Symbols:\n");
	while(t->alphabet[i])
	{
        printf("%d: %c\n",i+1,t->alphabet[i]);
        i++;
    }
}

void
printStates(t_table * t)
{
    int i,j, firstPrint;

	printf("\nStates:\n");
	for(i=0;i<t->states.dim;i++)
	{
	   printf("%d: %d [",i,t->states.vec[i]);
	   if(t->states.vec[i] < t->originalDim)
	       printf("%d",t->states.vec[i]);
        else
            for(j=0, firstPrint=1;(1<<j)<t->states.vec[i]-t->originalDim;j++)
                if((1<<j) & (t->states.vec[i]-t->originalDim))
                {
                    if(!firstPrint)
                        putchar('-');
                    printf("%d",j);
                    firstPrint=0;
                }
	    printf("]\n");
    }
}


void
printTable(t_table * t)
{
    int i,j;

    printf("\nPrinting transition table...\n");
    printf("   |    ");
    for(i=0;i<t->transitions.cols-1;i++)
        printf("%c\t",t->alphabet[i]);
    printf("^\n");
    for(i=0;i<t->transitions.cols*6+8;i++)
        putchar('-');
    printf("\n");
        
    for(i=0;i<t->transitions.fils;i++)
    {
        printf("%d  |   ",i);
        for(j=0;j<t->transitions.cols;j++)
            printf("%d\t",t->transitions.data[i][j]);
        printf("\n");
    }
}

void
error(int critical, char * msg)
{
    fprintf(stderr,"%s\n",msg);
    system("PAUSE");	
    if(critical)
        exit(EXIT_FAILURE);
}
